class A_ALG{ETP,ATP<$ARR{ETP}}
****
Miscellaneous array algorithms Usage:
_____a:_ARRAY{FLT}_:=_|1.0,2.0,3.0,3.0|;
_____a_alg:_A_ALG{INT,ARRAY{INT}};_--_dummy_variable
_____Counting_3s_in_the_array
_______number_of_threes:_INT_:=_a_alg.count(a,3.0);
_____Getting_an_array_of_indices
_______index_array:ARRAY{INT}_:=_a_alg.inds(a);


Ancestors
COMPARE{_}



Public


Features
count(a: ATP,v:ETP):INT
**** The number of elements that are `elt_eq' to `v'.
elt_eq(e1,e2:ETP):BOOL .. Included as elt_eq
**** The "less than" relation used in the sorting routines. Compares the object "id" by default. May be redefined in descendants.
elt_hash(e:ETP):INT .. Included as elt_hash
**** A hash value associated with an element. Must have the property that if "elt_eq(e1,e2)" then "elt_hash(e1)=elt_hash(e2)". Can be defined to always return 0, but many routines will then become quadratic. Uses object "id" by default. May be redefined in descendants.
elt_lt(e1,e2:ETP):BOOL .. Included as elt_lt
**** The "less than" relation used in the sorting routines. Compares the object "id" by default. May be redefined in descendants.
elt_nil: ETP .. Included as elt_nil
**** Return the nil value. If the element is under $NIL then return e.nil. Otherwise, return void
_
equals(a: ATP,e: $ARR{ETP}): BOOL
**** Returns true if all of "e"'s elements are equal to a's elts
inds(a: ATP): ARRAY{INT}
**** Return an index array which is the same size as self and is set to the values of the indices
is_elt_nil(e:ETP):BOOL .. Included as is_elt_nil
map(a: ATP,r:ROUT{ETP}:ETP)
**** Set each element of self to the result of applying `r' to it.
mismatch(a:ATP,pattern: ARRAY{ETP}):INT
**** The index of the first element of self which differs from `a'. -1 if self is a prefix of `a' or self is void.
reduce(a:ATP, r:ROUT{ETP,ETP}:ETP, start_value:ETP) :ETP
**** Combine all the elements of self by applying `r' over elements in the order determined by ind!
replace(a: ATP, old_elt,new_replacement: ETP)
**** Replace elements that are `elt_eq' to `o' by `n' wherever it occurs
replace_if(a: ATP,test: ROUT{ETP}:BOOL,replacement_value: ETP)
scan(a:ATP, r:ROUT{ETP,ETP}:ETP, start_value:ETP)
**** Set each element in a to the result of applying `r' left to right to the array up to the element. The first element is left unchanged.
str(a: ATP): STR
**** Prints out a string version of the array of the components that are under $STR, and their associated indices


Private

elt_str(e: ETP,i: INT): STR

The Sather Home Page